package com.burpee.dao;

import java.util.List;

import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.burpee.ui.Authority;
import com.burpee.ui.Member;
import com.burpee.ui.Statistics;
@Repository(value="memberDao")
public class MemberDaoImpl implements MemberDao {
	
	SqlSessionTemplate sqlSessionTemplate;
	
	@Autowired
	public void setSqlSessionTemplate(SqlSessionFactory sqlSessionFactory) {
		this.sqlSessionTemplate = new SqlSessionTemplate(sqlSessionFactory);
	}

	public boolean login(Member member) {
		
		Member member2 = new Member();
		
		try {
			member2= sqlSessionTemplate.selectOne("login",member);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		if(member2 != null){
			return true;
		} else {
			return false;
		}
			
	}
	
	
	
	public List<Member> list() {
		
		List<Member> memberlList = null;
		
		try {
			memberlList = sqlSessionTemplate.selectList("memberList");
		} catch (Exception e) {
			e.printStackTrace();
		}

		return memberlList;
	}

	public Member view(String memberId) {
		Member member = new Member();

		try {
			member = sqlSessionTemplate.selectOne("memberView", memberId);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return member;
	}
	
	public int memberadd(Member member) {
		int result = 0;
		
		try {
			result = sqlSessionTemplate.insert("memberAdd",member);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return result;
	}

	public int membermodify(Member member) {
		
		int result = 0;
		
		result = sqlSessionTemplate.update("memberModify", member);
		
		return result;
	}
	
	
	
}
